package com.learn.annotation_config.resource.beans.service;

import com.learn.annotation_config.resource.beans.dao.UserDao;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component("userService")
public class UserServiceImpl implements UserService {
    // 当接口存在多个实现类时，以变量名为Bean在容器中的名称去查找对应的Bean注入
    @Resource
    private UserDao userDao1;
    
    @Resource(name = "userDao1")
    private UserDao userDao1Resource;
    
    @Resource(name = "userDao2")
    private UserDao userDao2Resource;
    
    public void show() {
        System.out.println("userDao1:" + userDao1); // 1
        System.out.println("userDao1Resource:" + userDao1Resource); // 1
        System.out.println("userDao2Resource:" + userDao2Resource); // 2
    }
}
